package com.uenpay.im.ui.old.activity.remark;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-3-22 下午6:56:47
 * @copyRight http://www.qiyunxin.com
 * @function TODO
 */
public class GetFriendMemoInvokeItem extends BaseHttpInvokeItem {

	public class GetFriendMemoInvokeItemResult extends HttpInvokeResult {
		public QYXUserEntity qyxUserEntity = new QYXUserEntity();
	}

	public GetFriendMemoInvokeItemResult getOutPut() {
		return (GetFriendMemoInvokeItemResult) GetResultObject();
	}

	/**
	 *
	 * @param custId
	 */
	public GetFriendMemoInvokeItem(String custId) {
		// http://api.qiyunxin.com/Friend/Friend/getFriendMemo?custid=
		String url = APIConfiguration.getBaseUrl()
				+ "Friend/Friend/getFriendMemo?custid=" + custId +"&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetFriendMemoInvokeItemResult result = new GetFriendMemoInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");

		JSONObject dataJson = json.optJSONObject("data");
		if (dataJson != null) {
			result.qyxUserEntity = desQYXUserEntity(dataJson);
		}
		return result;
	}

	private QYXUserEntity desQYXUserEntity(JSONObject json) {
		QYXUserEntity mQYXUserEntity = new QYXUserEntity();
		mQYXUserEntity.custid = json.optString("custid");
		mQYXUserEntity.remarkname = json.optString("nickname");
		mQYXUserEntity.remarkPhonenumber = json.optString("phonenumber");
		mQYXUserEntity.remarkMemo = json.optString("memo");
		return mQYXUserEntity;
	}
}
